#! /bin/bash
HIVE_HOME=/usr/bin/hive

Last_Month=$(date -d "$(date +%Y%m)01 last month" +%Y-%m-01)
${HIVE_HOME} -S -e "
--分区
SET hive.exec.dynamic.partition=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions.pernode=10000;
set hive.exec.max.dynamic.partitions=100000;
set hive.exec.max.created.files=150000;
--hive压缩
set hive.exec.compress.intermediate=true;
set hive.exec.compress.output=true;
--写入时压缩生效
set hive.exec.orc.compression.strategy=COMPRESSION;
--分桶
set hive.enforce.bucketing=true;
set hive.enforce.sorting=true;
set hive.optimize.bucketmapjoin = true;
set hive.auto.convert.sortmerge.join=true;
set hive.auto.convert.sortmerge.join.noconditionaltask=true;
--并行执行
set hive.exec.parallel=true;
set hive.exec.parallel.thread.number=8;
--矢量化查询
set hive.vectorized.execution.enabled=true;
--关联优化器
set hive.optimize.correlation=true;
--读取零拷贝
set hive.exec.orc.zerocopy=true;
--join数据倾斜
set hive.optimize.skewjoin=true;
-- set hive.skewjoin.key=100000;
set hive.optimize.skewjoin.compiletime=true;
set hive.optimize.union.remove=true;

INSERT into itcast_dwm.customer_signup_dwm PARTITION (payment_time_year, payment_time_month, payment_time_day)
SELECT
    dwd.customer_id,
    clazz.itcast_school_id,
    clazz.itcast_school_name,
    clazz.itcast_subject_id,
    clazz.itcast_subject_name,
    e.tdepart_id,
    dept.name as tdepart_name,
    dwd.origin_type,
    dwd.origin_type_stat,
    dwd.payment_time_hour,
    dwd.payment_time_year,
    dwd.payment_time_month,
    dwd.payment_time_day
FROM itcast_dwd.customer_relationship_dwd dwd
LEFT JOIN itcast_dimen.itcast_clazz clazz on dwd.itcast_clazz_id=clazz.id
LEFT JOIN itcast_dimen.employee e on dwd.creator=e.id
LEFT JOIN itcast_dimen.scrm_department dept on e.tdepart_id=dept.id
where substr(dwd.payment_time, 1, 10) >= '$Last_Month' ;"